package gui.awt.listener;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestAction02 {
    //两个按钮，监听同一个事件
    //开始，停止

    public static void main(String[] args) {
        Frame f = new Frame("start-end");
        Button b1 = new Button("start");
        Button b2 = new Button("end");

        //不显示定义，则回发送label的值
        b2.setActionCommand("end");
        b1.setActionCommand("start");

        MyMonitor myMonitor = new MyMonitor();
        b1.addActionListener(myMonitor);
        b2.addActionListener(myMonitor);

        f.add(b1,BorderLayout.SOUTH);
        f.add(b2,BorderLayout.NORTH);

        f.setBounds(200,200,200,200);
        f.setVisible(true);

    }

}

class MyMonitor implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println(e.getActionCommand());
    }
}